package fhp.hlhj.giantfold.fragment

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.kepler.jd.login.KeplerApiManager
import com.kepler.jd.sdk.bean.KeplerAttachParameter
import com.zipingfang.android.yst.ui.utils.GoodsUtils
import fhp.hlhj.giantfold.Contents
import fhp.hlhj.giantfold.MainActivity
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.activity.login.WechatLoginAty
import fhp.hlhj.giantfold.activity.malls.TBOrderListAty
import fhp.hlhj.giantfold.activity.red.ShakeRedAty
import fhp.hlhj.giantfold.activity.user.HelpCenterAty
import fhp.hlhj.giantfold.activity.user.OrderAty
import fhp.hlhj.giantfold.utils.LogUtil
import kotlinx.android.synthetic.main.nav_fgm.view.*

/**
 * Created by Administrator on 2018\3\5 0005.
 */
class NavFragment :Fragment(){
    private lateinit var rootView:View
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        rootView= inflater.inflate(R.layout.nav_fgm,null)


        rootView.btHelp.setOnClickListener{
            if (Contents.userId.equals("0")){
                val intent =Intent(activity, WechatLoginAty::class.java)
                activity.startActivityFromFragment(this,intent,1)
                }
            else{
                GoodsUtils.showChatActivity(context,object : GoodsUtils.ChatActivityListener{
                    override fun afterShow() {
                    }

                    override fun beforeShow() {
                    }
                })
            }

        }

        rootView.tbOrder.setOnClickListener {
            if (Contents.userId.equals("0")){
                val intent =Intent(activity, WechatLoginAty::class.java)
                activity.startActivityFromFragment(this,intent,1)
            }
            else{
                context.startActivity(Intent(context,TBOrderListAty::class.java))
            }
        }

        rootView.btJDOrder.setOnClickListener{
            if (Contents.userId.equals("0")){
                val intent =Intent(activity, WechatLoginAty::class.java)
                activity.startActivityFromFragment(this,intent,1)
            }
            else{
                val parameter = KeplerAttachParameter()

                parameter.setCustomerInfo("hlhjjz")
                KeplerApiManager.getWebViewService().openCartWebViewPage(parameter)
            }

        }
        rootView.btShake.setOnClickListener {
            if (Contents.userId.equals("0")){
                val intent =Intent(activity, WechatLoginAty::class.java)
                activity.startActivityFromFragment(this,intent,1)
            }
            else{

                context.startActivity(Intent(context,ShakeRedAty::class.java))
            }
        }
        rootView.btOrder.setOnClickListener{
            if (Contents.userId.equals("0")){
                val intent =Intent(activity, WechatLoginAty::class.java)
                activity.startActivityFromFragment(this,intent,1)
            }
            else{
                context.startActivity(Intent(context,OrderAty::class.java))
            }
        }
        rootView.btHelpCenter.setOnClickListener {
            if (Contents.userId.equals("0")){
                val intent =Intent(activity, WechatLoginAty::class.java)
                activity.startActivityFromFragment(this,intent,1)
            }
            else{
                context.startActivity(Intent(context,HelpCenterAty::class.java))
            }
        }
        return rootView

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        LogUtil.log("---------------------------来了来了$resultCode")

        if (resultCode!= Activity.RESULT_OK)return
        when(requestCode){
            1->{
                LogUtil.log("---------------------------来了来了")
                val ft = fragmentManager.beginTransaction()
                ft.hide(this)
                ft.commit()
                val mainActivity = activity as MainActivity
                mainActivity.change(R.id.rbSpend)
            }
        }
    }
}